package cn.kgc.music.controller;

import cn.kgc.music.pojo.FormComment;
import cn.kgc.music.pojo.User;
import cn.kgc.music.service.FormCommentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.stream.events.Comment;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/formcomment")
public class FormCommentController {
    @Resource
    FormCommentService formCommentService;
    @RequestMapping("queryformcomment.do")
    @ResponseBody
    public Map<String,Object> queryFormComment(HttpServletRequest request){
        Map<String,Object> map=new HashMap<>();
        List<FormComment> formComments = formCommentService.queryFormComment(1);
        map.put("formComments",formComments);
        return map;
    }

    @RequestMapping("addformcomment.do")
    @ResponseBody
    public Map<String,Object> addFormComment(String commemt,HttpServletRequest request){
        Map<String,Object> map=new HashMap<>();
        System.out.println(commemt);
        User user = (User) request.getAttribute("usr");
        System.out.println(user);
        int i = formCommentService.addFormComment(1, 1, commemt);
        if(i>0){
            map.put("addmsg","cg");
        }else{
            map.put("addmsg","sb");
        }
        return  map;
    }
}
